import CryptoJs from "crypto-js";

const str = "0jiuse0@it_0dept_0js";

export interface CryptoType {
  encrypt: any;
  decrypt?: any;
}

export default class Crypoto implements CryptoType {
  key = CryptoJs.enc.Utf8.parse(this.changeKey(str));

  /** 加密 */
  encrypt(word: string) {
    const iv = CryptoJs.lib.WordArray.random(16);
    const encrypted = CryptoJs.AES.encrypt(word, this.key, {
      iv: iv
    });
    return iv.concat(encrypted.ciphertext).toString(CryptoJs.enc.Base64);
  }

  changeKey(str: string) {
    return str.replace(/0/g, "");
  }
}
